/** WMI SYSTEM TOOLS
*	JScript interfaces for WMI System Info Functions
*		version 0.1 (1.25.2008)
*		Matthew Smith
*		http://digivation.net/
*
*	Licensed for use under the GPL
*
*
*	Version History
*	x.x	released?
*
*/

/** GET SYSTEM INFO
* INPUT: computer as string, use "." for local
* OUTPUT: returns object containing the following information
*	Name				Returns				Type
*  =============================================================
*	UserName			the username 		string
*	SystemBrand			pc brand			string
*	SystemModel			pc model			string
*	SystemRam			ram in MB			number
* 	OS					OS Name				string
* 	OSVersion			OS Version			string
* 	OSServicePack		Service Pack		number
* 	OSPath				system directory	string
*  =============================================================
*/

function systemToolsGetSettings(computer) {
	var SystemSettings = new Array();
	
	var WMIService = GetObject("winmgmts:\\\\" + computer + "\\root\\CIMV2"); // connect to WMI service
	var colComputer = WMIService.ExecQuery("SELECT * FROM Win32_ComputerSystem"); // get the computer
	var colOperatingSystems = WMIService.ExecQuery("SELECT * FROM Win32_OperatingSystem") // get the collection of OS info
	var enumComputer = new Enumerator(colComputer); // create enumerator for computer
	var enumOperatingSystems = new Enumerator(colOperatingSystems); // create enumerator for OS
	
	var objComputer = enumComputer.item(); // grab the Computer object from our query
	var objOperatingSystem = enumOperatingSystems.item(); // grab the OS item from the above query (not sure what happens with multiple os's)
	
	// let's get some params from objComputer
	SystemSettings.UserName = objComputer.UserName;
	SystemSettings.SystemBrand = objComputer.Manufacturer;
	SystemSettings.SystemModel = objComputer.Model;
	SystemSettings.SystemRam = (objComputer.TotalPhysicalMemory / (1024*1024));
	
	// and more from objOperatingSystem
	SystemSettings.OS = objOperatingSystem.Caption;
	SystemSettings.OSVersion = objOperatingSystem.Version;
	SystemSettings.OSServicePack = objOperatingSystem.ServicePackMajorVersion;
	SystemSettings.OSPath = objOperatingSystem.WindowsDirectory;
	
	return SystemSettings;
}

function systemToolsExecuteCmd(computer, command) {
	var WMIService = GetObject("winmgmts:{impersonationLevel=impersonate}!\\\\" + computer + "\\root\\CIMV2");
	var objRunner = WMIService.Get("Win32_Process");
	
	objRunner.Create(command);
}